#region Summary 

// 
// Owner : JackieHan 
// 
// Solution : Jackie.Utility
// 
// Project :Jackie.Utility.Test
// 
// File : TestValidate.cs
// 
// CopyRight : Copyright © 2009-2010 JackieHan Personal, All Rights Reserved 
// 
// Summary : 测试自定义验证
// 
// History : 
//			2010-09-02 14:20:46	    Create 
// 

#endregion

#region Using 

using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;

#endregion

namespace Jackie.Utility.Test
{
    /// <summary> 
    /// 测试自定义验证
    /// </summary> 
    [TestFixture]
    public class TestValidate
    {
        [Test]
        public void TestIsCollection()
        {
            Type type = typeof (string);
            bool isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof (NormalClass);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(false, isCollection);

            type = typeof (List<NormalClass>);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof(Array);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof(int[]);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof(string[]);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof(IList<NormalClass>);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof(Hashtable);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof(HashSet<NormalClass>);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);

            type = typeof(Dictionary<string,NormalClass>);
            isCollection = JackieValidator.IsCollection(type);
            Assert.AreEqual(true, isCollection);
        }

        private class NormalClass
        {
            
        }

        [Test]
        public void TestIsFileExtension()
        {
            IList<string> extensions = new List<string> {".xml", ".xls", ".csv"};
        }

        [Test]
        public void TestEnumType()
        {
            FileType fileType = FileType.Text | FileType.Xml;

            Assert.AreEqual(true, (fileType & FileType.Text)==FileType.Text);
            Assert.AreEqual(false, (fileType & FileType.Excel) == FileType.Excel);

            fileType = FileType.Excel;
            Assert.AreEqual(true, (fileType & FileType.Excel) == FileType.Excel);
            Assert.AreEqual(false, (fileType & FileType.Text) == FileType.Text);
        }

        [Test]
        public void TestIsFileExtensions()
        {
            string file = "a.xml";
            bool isXmlFile = JackieValidator.IsFileExtension(file, FileType.Xml);
            Assert.AreEqual(true, isXmlFile);

            file = "bbb";
            isXmlFile = JackieValidator.IsFileExtension(file, FileType.Xml);
            Assert.AreEqual(false, isXmlFile);
        }
    }
}